#include "comm.hpp"

int main()
{
    key_t key = ftok(PATH_NAME, PROJ_ID);
    if(key < 0)
    {
        perror("ftok");
        return 1;
    }
    cout << "key:" << key << endl;
    //client这里只需要获取即可
    int shmid = shmget(key, SIZE, IPC_CREAT);
    if(shmid < 0)
    {
        perror("shmget");
        return 1;
    }
    char* mem = (char*)shmat(shmid, NULL, 0);
    //sleep(5);
    cout << "client process attaches success..." << endl;
    //在共享内存中写入数据
    char c = 'A';
    while(c <= 'Z')
    {
        mem[c - 'A'] = c;
        c++;
        mem[c - 'A'] = 0;
        //sleep(1);
    }

    shmdt(mem);
    //sleep(5);

    cout << "client process detaches success..." << endl;
    cout << key << endl;
    return 0;
}